package mhwi.modcore;

import basemod.BaseMod;
import basemod.helpers.RelicType;
import basemod.interfaces.*;
import com.badlogic.gdx.Gdx;
import com.evacipated.cardcrawl.modthespire.lib.SpireInitializer;
import com.google.gson.Gson;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.localization.*;
import mhwi.cards.hunter.*;
import mhwi.cards.taidao.*;
import mhwi.characters.TaiDaoHunter;
import mhwi.helper.ModHelper;
import mhwi.relics.CangLanXingRelic;
import mhwi.relics.TaiDaoRelic;

import java.nio.charset.StandardCharsets;

import static com.megacrit.cardcrawl.core.Settings.language;
import static mhwi.constants.CharacterConstants.*;
import static mhwi.constants.ColorConstant.COLOR_HUNTER;
import static mhwi.constants.ModInfoConstant.MOD_ID;
import static mhwi.constants.ResourcesConstant.*;
import static mhwi.enums.ModEnums.PlayerColorEnum.*;

/***
 *                      M     M   oooo   nnnnn   SSSSS  TTTTT  EEEEE  RRRR
 *                      MM   MM  oo  oo  n   n  S         T    E      R   R
 *                      M M M M  oo  oo  n   n   SSSS     T    EEEE   RRRR
 *                      M  M  M  oo  oo  n   n       S    T    E      R  R
 *                      M     M   oooo   n   n   SSSS     T    EEEEE  R   R
 *
 *                          H   H  U   U  N   N  TTTTT  EEEEE  RRRR
 *                          H   H  U   U  NN  N    T    E      R   R
 *                          HHHHH  U   U  N N N    T    EEEE   RRRR
 *                          H   H  U   U  N  NN    T    E      R  R
 *                          H   H   UUU   N   N    T    EEEEE  R   R
 */

@SpireInitializer
public class MonsterHunterWorldIceborne implements
        EditCardsSubscriber, EditStringsSubscriber, EditCharactersSubscriber, EditRelicsSubscriber, EditKeywordsSubscriber {
    public MonsterHunterWorldIceborne() {
        BaseMod.subscribe(this);
        // 注册颜色
        // hunter
        BaseMod.addColor(CARD_COLOR_HUNTER,
                COLOR_HUNTER, COLOR_HUNTER, COLOR_HUNTER, COLOR_HUNTER, COLOR_HUNTER, COLOR_HUNTER, COLOR_HUNTER,
                BG_ATTACK_512,BG_SKILL_512,BG_POWER_512,ENEYGY_ORB,BG_ATTACK_1024,BG_SKILL_1024,BG_POWER_1024,BIG_ORB,SMALL_ORB);
        // 太刀
        BaseMod.addColor(CARD_COLOR_HUNTER_TAIDAO,
                COLOR_HUNTER, COLOR_HUNTER, COLOR_HUNTER, COLOR_HUNTER, COLOR_HUNTER, COLOR_HUNTER, COLOR_HUNTER,
                BG_ATTACK_512,BG_SKILL_512,BG_POWER_512,ENEYGY_ORB,BG_ATTACK_1024,BG_SKILL_1024,BG_POWER_1024,BIG_ORB,SMALL_ORB);
    }

    public static void initialize() {
        new MonsterHunterWorldIceborne();
    }

    // 注册卡牌
    @Override
    public void receiveEditCards() {
        BaseMod.addCard(new XiaoJuHeCard());
        BaseMod.addCard(new DaJuHeCard());
        BaseMod.addCard(new TeShuNaDaoCard());
        BaseMod.addCard(new ShouQiWuQiCard());
        BaseMod.addCard(new FanGunCard());
        BaseMod.addCard(new TaBuZhanCard());
        BaseMod.addCard(new TuCiCard());
        BaseMod.addCard(new HouTuiZhanCard());
        BaseMod.addCard(new ShangTiaoZhanCard());
        BaseMod.addCard(new LiShiCard());
        BaseMod.addCard(new XinHaoDanCard());
        BaseMod.addCard(new MiYaoCard());
        BaseMod.addCard(new YingHuaYaoCard());
        BaseMod.addCard(new WuQiPaiShengCard());
        BaseMod.addCard(new GuiRenYaoCard());
        BaseMod.addCard(new HuiFuYaoCard());
        BaseMod.addCard(new MoDaoShenYuDeQiCard());
        BaseMod.addCard(new XianJingCard());
        BaseMod.addCard(new FeiPuCard());
        BaseMod.addCard(new QiRenTuCiCard());
        BaseMod.addCard(new QiRenDouGeCard());
        BaseMod.addCard(new TiCaoKaiRenCard());
        BaseMod.addCard(new RuanHuaCard());
        BaseMod.addCard(new ShanGuangDanCard());
        BaseMod.addCard(new JianQieCard());
        BaseMod.addCard(new MaoFanCard());
        BaseMod.addCard(new YuanQiYinLiaoCard());
        BaseMod.addCard(new DaXiaoGuoShiCard());
    }

    // 注册角色
    @Override
    public void receiveEditCharacters() {
        // 太刀
        BaseMod.addCharacter(new TaiDaoHunter(CardCrawlGame.playerName),
                CHARACTER_BUTTON_TAIDAO, CHARACTER_PORTRAIT_TAIDAO, PLAYER_CLASS_TAIDAO);
    }

    // 注册遗物
    @Override
    public void receiveEditRelics() {
        BaseMod.addRelic(new CangLanXingRelic(), RelicType.SHARED); // 苍蓝星
        BaseMod.addRelic(new TaiDaoRelic(), RelicType.SHARED); // 太刀
    }

    // 注册关键词
    @Override
    public void receiveEditKeywords() {
        Gson gson = new Gson();
        String lang = "eng";
        if (language == Settings.GameLanguage.ZHS) {
            lang = "zhs";
        }

        String finalLang = "/" + lang + "/";
        String json = Gdx.files.internal(ModHelper.makePath(PATH_LOCALIZATION, finalLang, LOCALIZATION_KEYWORDS))
                .readString(String.valueOf(StandardCharsets.UTF_8));
        Keyword[] keywords = gson.fromJson(json, Keyword[].class);
        if (keywords != null) {
            for (Keyword keyword : keywords) {
                BaseMod.addKeyword(MOD_ID, keyword.NAMES[0], keyword.NAMES, keyword.DESCRIPTION);
            }
        }
    }

    // 本地化
    @Override
    public void receiveEditStrings() {
        String lang;
        if (Settings.language == Settings.GameLanguage.ZHS) {
            lang = "zhs";
        } else {
            lang = "eng";
        }
        String finalLang = "/" + lang + "/";
        // 卡牌
        BaseMod.loadCustomStringsFile(CardStrings.class, PATH_LOCALIZATION + finalLang + LOCALIZATION_CARDS);
        // 角色
        BaseMod.loadCustomStringsFile(CharacterStrings.class, PATH_LOCALIZATION + finalLang + LOCALIZATION_CHARACTERS);
        // 遗物
        BaseMod.loadCustomStringsFile(RelicStrings.class, PATH_LOCALIZATION + finalLang + LOCALIZATION_RELICS);
        // 能力
        BaseMod.loadCustomStringsFile(PowerStrings.class, PATH_LOCALIZATION + finalLang + LOCALIZATION_POWERS);
        // 敌人
//        BaseMod.loadCustomStringsFile(MonsterStrings.class, PATH_LOCALIZATION + finalLang + LOCALIZATION_MONSTERS);
    }
}
